package com.example.hospital.mapper;


import com.example.hospital.pojo.ShiftSwap;
import org.apache.ibatis.annotations.*;

import java.util.List;

/*调班mapper接口*/
@Mapper
public interface ShiftSwapMapper {

    @Select("SELECT * FROM shift_swap WHERE requester_id = #{requesterId} OR receiver_id = #{receiverId}")
    /*这里传入多个参数mybatis识别不到,需要使用到Param注解进行绑定*/
    List<ShiftSwap> findByUserId(@Param("requesterId") Integer requesterId,@Param("receiverId") Integer receiverId);

    @Select("SELECT * FROM shift_swap")
    List<ShiftSwap> findAll();

    @Select("SELECT * FROM shift_swap WHERE id = #{id}")
    ShiftSwap findById(Integer id);

    @Insert("INSERT INTO shift_swap(requester_id, receiver_id, date, status, created_at, updated_at) " +
            "VALUES(#{requesterId}, #{receiverId}, #{date}, #{status}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertShiftSwap(ShiftSwap shiftSwap);

    @Update("UPDATE shift_swap SET status=#{status}, updated_at=NOW() WHERE id=#{id}")
    void updateShiftSwap(ShiftSwap shiftSwap);
}
